import { MPromise } from "./MPromise";

class MKeysInstance {
    public static readonly Instance: MKeysInstance = new MKeysInstance();
    private constructor() { }

    initMKeys(): void {
        // 测试promise
        MPromise.initMPromise();


        // this.constructorKey();
        // this.asKey();
    }


    // 1.constructor：this['constructor']函数类型(function)
    // 2.name：MKeysInstance 需在 tsconfig.json 增加 "lib": [ es2015.promise ]
    constructorKey()  {
        console.log(this['constructor']);               //function MKeysInstance() { … }
        console.log(this['constructor'].name);          //MKeysInstance

        this.testConstructor(this['constructor'] as { new(): MKeysInstance });
    }
    testConstructor(cName: { new(): MKeysInstance }) {
        new cName().testConstructor2();
    }
    testConstructor2() {
        //console.log('testConstructor2');
    }

    
    // 2.as(类型断言)：值 as 类型
    asKey() {
        //1.
        let val: any = 1;
        let str: string = val as string;
        console.log(typeof (str));              //number类型
    }
}



class ConstructorTest {
    constructor() { 
        console.log('ConstructorTest')
    }
}


export const MKeys = MKeysInstance.Instance;
